<?php
namespace Tbf\Bundle\DatabaseBundle\DataSet;
class DbDataSet
{
    protected $data;
    public function __construct(array $data=array())
    {
        $this->data = $data;
    }
    public static function fromArray(array $data)
    {
        return new static($data);
    }
    public function toArray()
    {
        return $this->data;
    }
    /**
     * 向每张表后面添加数据
     */
    public function append(DbDataSet $data_set)
    {
        foreach ($data_set->toArray() as $table_name=>$table_data) {
            if (empty($this->data[$table_name])) {
                $this->data[$table_name] = array();
            }
            $this->data[$table_name] =
                array_merge($this->data[$table_name],$table_data);
        }

        return $this;
    }
    /**
     * 给某些表重新设置数据
     */
    public function set(DbDataSet $data_set)
    {
        foreach ($data_set->toArray() as $table_name=>$table_data) {
            $this->data[$table_name] = $table_data;
        }

        return $this;
    }
}
